package com.longrise.android.byjk.plugins.hra.hratabfirst;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.SparseArray;

import com.longrise.android.byjk.plugins.hra.BaseFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/5.
 */

public class HraPlacesPagerAdapter extends BaseFragmentPagerAdapter {


    //保存每个Fragment的Tag，刷新页面的依据
    protected SparseArray<String> tags = new SparseArray<>();
    private List<OrderPlaceParentBean> mParentList = new ArrayList<>();

    public HraPlacesPagerAdapter(FragmentManager fragmentManager){
        super(fragmentManager);
    }


    public void setData(List<OrderPlaceParentBean> parentList) {
        mParentList.clear();
        mParentList.addAll(parentList);
        this.notifyDataSetChanged();
    }


    @Override
    public Fragment getItem(int position) {
        HraPlacesFragment fragment = new HraPlacesFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(HraPlacesFragment.HRAPLACEFAGMENT,mParentList.get(position));
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getCount() {
        return mParentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        OrderPlaceParentBean orderPlaceParentBean = mParentList.get(position);
//        String placeDate = orderPlaceParentBean.getBespeakdate();
        String placeDate = orderPlaceParentBean.getNewDate();
        return placeDate;
    }

    @Override
    public int getItemPosition(Object object) {
        Fragment fragment = (Fragment) object;
        //如果Item对应的Tag存在，则不进行刷新
        if (tags.indexOfValue(fragment.getTag()) > -1) {
            return super.getItemPosition(object);
        }
        return POSITION_NONE;
    }

}

